<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程管理</el-breadcrumb-item>
      <el-breadcrumb-item>任务管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20" class="el-row-table">
        <el-col :span="12"
          ><div class="grid-content bg-purple">
            <el-input
              placeholder="请输入内容"
              v-model="queryInfo.name"
              clearable
              @clear="getTaskList"
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="getTaskList"
              ></el-button>
            </el-input></div
        ></el-col>

        <el-col :span="10">
          <div class="grid-content bg-purple">
            <el-button type="success" @click="getTaskList">刷新</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple">
            <el-button type="primary" @click="toCourse">返回</el-button>
          </div>
        </el-col>
      </el-row>

      <!-- 课程列表区域 -->
      <el-table border stripe width="100%" :data="taskList">
        <el-table-column fixed prop="id" label="编号"> </el-table-column>
        <!-- <el-table-column fixed prop="longitude" label="经度" width="100">
        </el-table-column>
        <el-table-column fixed prop="latitude" label="纬度" width="100">
        </el-table-column> -->
        <el-table-column fixed prop="clockInCount" label="已签到人数">
        </el-table-column>

        <el-table-column fixed prop="allCount" label="班级人数">
        </el-table-column>
        <el-table-column fixed prop="experience" label="经验值">
        </el-table-column>
        <el-table-column fixed label="是否限时签到">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.limited" disabled> </el-switch>
          </template>
        </el-table-column>
        <el-table-column fixed prop="ended" label="是否结束"> </el-table-column>

        <el-table-column fixed prop="createTime" label="创建时间">
        </el-table-column>
        <el-table-column fixed label="操作">
          <template slot-scope="scope">
            <!-- 第一个是查看签到按钮 -->
            <el-tooltip
              effect="dark"
              content="查看签到名单"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="success"
                icon="el-icon-s-claim"
                circle
                @click="toCheckClockIn(scope.row.id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.current"
        :page-sizes="[5, 10]"
        :page-size="queryInfo.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { pageTask } from "@/api/task.js";
import { getCourse } from "@/api/course.js";
export default {
  data() {
    return {
      //获取课程列表的参数对象
      queryInfo: {
        current: 1,
        size: 5,
      },
      taskList: [],
      total: 0,

      //控制查看课程信息对话框的显示与隐藏
      showTaskDialogVisible: false,
      //查询到的课程信息对象
      showForm: {},
    };
  },
  created() {
    this.getTaskList();
  },
  methods: {
    async getTaskList() {
      var courseId = JSON.parse(localStorage.getItem("courseToTaskId"));
      const { data: res } = await pageTask(
        this.queryInfo.current,
        this.queryInfo.size,
        courseId
      );
      this.taskList = res.data.records;

      this.taskList.forEach((element) => {
        //这里是转变true和false的显示
        element.ended = element.ended ? "是" : "否";
      });

      this.total = res.data.total;
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.size = newSize;
      this.getTaskList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.current = newPage;
      this.getTaskList();
    },
    //跳转去查看签到人员名单
    toCheckClockIn(id) {
      localStorage.setItem("taskId", JSON.stringify(id));
      this.$router.push("/course/task/clockin");
    },

    toCourse() {
      this.$router.push("/course");
    },
  },
};
</script>

<style lang="less" scoped>
.breadcrumb {
  margin-bottom: 15px;
  font-size: 15px;
}
.box-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
.el-row-table {
  margin-bottom: 15px !important;
}
.el-pagination {
  margin-top: 15px;
}
</style>